"""
项目：Ai-Engineer自适应工程设计自动化插件
作者：刘昊轩、李佳音、刘伟伟、杨明久（排序不分先后）
©版权保护
"""
import logging
from datetime import datetime


class CADLogger:
    def __init__(self, name="AI-CAD"):
        self.logger = logging.getLogger(name)
        self.logger.setLevel(logging.DEBUG)

        # 文件日志
        file_handler = logging.FileHandler(f"log/cad_{datetime.now().strftime('%Y%m%d')}.log", encoding='gbk')
        file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))

        # 控制台日志
        console_handler = logging.StreamHandler()
        console_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))

        self.logger.addHandler(file_handler)
        self.logger.addHandler(console_handler)

    def log_command(self, command, success=True):
        self.logger.info(f"执行命令: {command} - 状态: {'成功' if success else '失败'}")

    def log_error(self, error):
        self.logger.error(f"错误发生: {str(error)}")

    def log_analysis(self, result):
        self.logger.debug(f"分析结果: {result}")